package com.cqrcb.cloud.controller.quota;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.cqrcb.cloud.config.annotation.CustomLogAnnotation;
import com.cqrcb.cloud.config.annotation.CustomValidation;
import com.cqrcb.cloud.controller.handler.BlockExceptionUtil;
import com.cqrcb.cloud.entity.api.req.Q;
import com.cqrcb.cloud.entity.api.res.R;
import com.cqrcb.cloud.entity.quota.io.CustomerMultiQuotaCtrlMarketMainIO;
import com.cqrcb.cloud.entity.quota.io.MultiQuotaCtrlMarketMainIO;
import com.cqrcb.cloud.service.quota.CustomerMultiQuotaCtrlMainService;
import com.cqrcb.cloud.service.quota.MultiQuotaCtrlMarketMainService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
* CustomerMultiQuotaCtrlMainController
*
* @author 系统
* @date 2021-06-19 04:39:42
*/
@Slf4j
@RestController
@RequestMapping("/user_quota")
@CrossOrigin
@Api(description = "额度扣减")
@SentinelResource(value="customSentinel",blockHandler="deduction2",blockHandlerClass = {BlockExceptionUtil.class})
public class CustomerMultiQuotaCtrlMainController {

    @Autowired
    public CustomerMultiQuotaCtrlMainService customerMultiQuotaCtrlMainService;

    @Autowired
    private MultiQuotaCtrlMarketMainService multiQuotaCtrlMarketMainService;

    @CustomValidation
    @CustomLogAnnotation
    @PostMapping("/deduction")
    public R deduction(@RequestBody Q<CustomerMultiQuotaCtrlMarketMainIO> customerMultiQuotaCtrlMarketMainIOQ) {
        log.info("这是什么-->>>");
        R r = customerMultiQuotaCtrlMainService.deductionFinancialProductQuota(customerMultiQuotaCtrlMarketMainIOQ);
        return r;
    }


    @CustomValidation
    @CustomLogAnnotation
    @PostMapping("/deduction2")
    public R deduction2(@RequestBody  Q<MultiQuotaCtrlMarketMainIO> multiQuotaCtrlMarketMainVoQ) {
        long time1 = System.currentTimeMillis();
        R r = multiQuotaCtrlMarketMainService.deductionFinancialProductQuota(multiQuotaCtrlMarketMainVoQ);
        long time2 = System.currentTimeMillis();
        log.info("本次耗时:{}",time2 - time1);
        return r;
    }


}